package com.qimou.iems.util;

import com.qimou.iems.entity.AdminUser;
import com.qimou.iems.entity.User;
import com.qimou.iems.exception.InterfaceCommonException;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class LoginHelper {



    public static final String LOGIN_SESSION = "session_user";



    public static AdminUser getCurrentUser() {
        HttpServletRequest req = ((ServletRequestAttributes) (RequestContextHolder.getRequestAttributes())).getRequest();
        AdminUser user = (AdminUser) req.getSession().getAttribute(LOGIN_SESSION);
        if (null == user) {
            throw new InterfaceCommonException(StatusConstant.NOTLOGIN, "未登录");
        }
        return user;
    }


}
